import { listCenter } from '@/api/center/center'
import { timestampToDate } from '@/utils/time'

/**
 * 通知列表
 */
class NoticeCenterList {
  component;
  /**
   * @param  {import("vue").Component}component
   */
  constructor(component) {
    this.component = component
  }

  /** 查询订单列表 */
  getList() {

    let queryParams = {
        pageNum: this.component.queryParams.pageNum,
        pageSize: this.component.queryParams.pageSize,
    }

    this.common(queryParams)
  }

  all() {

    let queryParams = {
        pageNum: this.component.queryParams.pageNum,
        pageSize: this.component.queryParams.pageSize,
    }

    this.common(queryParams)
  }

  /**
   * 合并两个数字
   * @param {number} cmd
   * @param {number} subcmd
   * @returns
   */
  merge(cmd, subcmd) {
    return (cmd << 16) + subcmd
  }

  /**
   * 订单通知
   */
  orderNotice() {
    this.tabParse(
      {
        pageNum: this.component.queryParams.pageNum,
        pageSize: this.component.queryParams.pageSize,
        noticeType:0
      },
    )
  }

  /**
   * 待支付
   */
  secondaryServiceNotice() {
    this.tabParse(
      {
        pageNum: this.component.queryParams.pageNum,
        pageSize: this.component.queryParams.pageSize,
        noticeType:1
      })
  }
  /**
   * 已完成
   */
  invoiceNotice() {
   this.tabParse(
      {
        pageNum: this.component.queryParams.pageNum,
        pageSize: this.component.queryParams.pageSize,
        noticeType:2
      })
  }

  teamNotice() {
   this.tabParse(
      {
        pageNum: this.component.queryParams.pageNum,
        pageSize: this.component.queryParams.pageSize,
        noticeType:3
      })
  }

  /**
   * 预存通知
   */
  depositNotice() {
    this.tabParse(
      {
        pageNum: this.component.queryParams.pageNum,
        pageSize: this.component.queryParams.pageSize,
        noticeType: 4
      })
  }

  /**
   * 处理中
   */
  withdrawalNotice() {
   this.tabParse(
      {
        pageNum: this.component.queryParams.pageNum,
        pageSize: this.component.queryParams.pageSize,
        noticeType: 5
      })
  }

  /**
   *
   * @param {{}} param
   */
  common(param) {
    this.component.loading = true
    listCenter(param).then((response) => {
      this.parseData(response)
    })
  }

  tabParse(param) {
    listCenter(param).then((res) => this.parseData(res))
  }

  parseData(response) {
    let orderList = response.rows

    // 循环 处理 parseTime
    // for (let i = 0; i < orderList.length; i++) {
    //   orderList[i].createTime = timestampToDate(orderList[i].createTime)
    //   if (0 == orderList[i].parseTime || null == orderList[i].parseTime) {
    //     orderList[i].parseTime = ''
    //     continue
    //   }
    //   orderList[i].parseTime = timestampToDate(orderList[i].parseTime)
    // }
    this.component.centerList = orderList;
    this.component.total = response.total;
    this.component.loading = false
  }
}

export { NoticeCenterList }
